import process from 'node:process'

import { fileURLToPath, URL } from 'node:url'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
import UnoCSS from 'unocss/vite'
import { defineConfig, loadEnv } from 'vite'
import vueDevTools from 'vite-plugin-vue-devtools'

// https://vite.dev/config/
export default defineConfig(({ mode }) => {
  const env = loadEnv(mode, process.cwd()) as unknown as ImportMetaEnv
  return {
    plugins: [vue(), vueJsx(), vueDevTools(), UnoCSS()],
    resolve: {
      alias: {
        '@': fileURLToPath(new URL('./src', import.meta.url)),
      },
    },
    server: {
      proxy: {
        [env.VITE_GLOB_API_URL_PREFIX]: {
          target: env.VITE_GLOB_API_URL,
          changeOrigin: true,
        },
      },
    },
    esbuild: {
      drop: ['debugger'],
      pure: ['console.log'],
    },
  }
})
